﻿namespace ACCOUNTING.LVY.Business
{
    using ACCOUNTING;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Data;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;

    public class clsDonDatHang
    {
        private double mDauVao = 0.0;
        private double mDauVaoNT = 0.0;
        private string mDiaChiDoiTuong = "";
        private string mDiaChiGiaoHang = "";
        private string mDienGiai = "";
        private string mHanGiaoCuoi = "";
        private double mHoaHong = 0.0;
        private double mHoaHongNT = 0.0;
        private string mKhoa = "";
        private string mKhoaBaoGia = "";
        private string mKhoaDoiTuong = "";
        private string mKhoaDonVi = "";
        private string mKhoaLoaiGia = "";
        private string mKhoaNhanVien = "";
        private string mKhoaNhanVienDuyet = "";
        private string mKhoaNhanVienSua = "";
        private string mKhoaNhanVienTao = "";
        private int mKiemTra = 0;
        private string mLoaiChungTu = "";
        private string mLoaiTien = "";
        private string mNgayChungTu = "";
        private string mNgayCungCap = "";
        private string mNgayDuyet = "";
        private string mNgayHangVeKho = "";
        private string mNgayHopDong = "";
        private string mNgaySua = "";
        private string mNgayTao = "";
        private string mNguoiLienHe = "";
        private string mPhuongThucGiaoHang = "";
        private string mPhuongThucThanhToan = "";
        private string mSoChungTu = "";
        private string mSoHopDong = "";
        private double mTienHang = 0.0;
        private double mTienHangNT = 0.0;
        private double mTienPhi = 0.0;
        private double mTienPhiNT = 0.0;
        private double mTienThue = 0.0;
        private double mTienThueNT = 0.0;
        private string mTinhTrang = "";
        private double mTyGia = 0.0;

        public void ClearTemp(string pKeyTable)
        {
            string commandText = "DELETE FROM BH_DonDatHangChiTietTmp WHERE KhoaDonDatHang = '" + pKeyTable.Trim() + "'";
            DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
        }

        public bool ConfirmOrder()
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[0x21];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, this.mKhoa);
                commandParameters[1] = DBHelper.createParameter("@TinhTrang", DbType.Int64, ParameterDirection.Input, this.mTinhTrang);
                commandParameters[2] = DBHelper.createParameter("@SoHopDong", DbType.Int64, ParameterDirection.Input, this.mSoHopDong);
                commandParameters[3] = DBHelper.createParameter("@NgayHopDong", DbType.Int64, ParameterDirection.Input, this.mNgayHopDong);
                commandParameters[4] = DBHelper.createParameter("@NgayHangVeKho", DbType.Int64, ParameterDirection.Input, this.mNgayHangVeKho);
                commandParameters[5] = DBHelper.createParameter("@pError", DbType.Double, ParameterDirection.Output, 0);
                DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "BH_sp_XacNhanDonHang", commandParameters);
                if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectNotEqual(commandParameters[5].Value, 0, false))
                {
                    return false;
                }
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool DeleteData(string strKhoa)
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[3];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, strKhoa);
                commandParameters[1] = DBHelper.createParameter("@pError", DbType.Double, ParameterDirection.Output, 0);
                int num = DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "BH_sp_DonDatHangDel", commandParameters);
                if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectNotEqual(commandParameters[1].Value, 0, false))
                {
                    return false;
                }
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool DuyetDonHang()
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[7];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, this.mKhoa);
                commandParameters[1] = DBHelper.createParameter("@DienGiai", DbType.Int64, ParameterDirection.Input, this.mDienGiai);
                commandParameters[2] = DBHelper.createParameter("@TinhTrang", DbType.Int64, ParameterDirection.Input, this.mTinhTrang);
                commandParameters[3] = DBHelper.createParameter("@SoHopDong", DbType.Int64, ParameterDirection.Input, this.mSoHopDong);
                commandParameters[4] = DBHelper.createParameter("@NgayHopDong", DbType.Int64, ParameterDirection.Input, this.mNgayHopDong);
                commandParameters[5] = DBHelper.createParameter("@KhoaNhanVienDuyet", DbType.Int64, ParameterDirection.Input, this.mKhoaNhanVienDuyet);
                commandParameters[6] = DBHelper.createParameter("@NgayDuyet", DbType.Int64, ParameterDirection.Input, this.mNgayDuyet);
                DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "BH_sp_DuyetDonHang", commandParameters);
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public DataTable GetDataPrint(string strKhoa, string strLanguage)
        {
            DataTable table;
            try
            {
                string commandText = "  SELECT DH.SoChungTu, dbo.Char2Date(DH.NgayChungTu) as NgayChungTu, Upper(RTrim(DT.Ten" + strLanguage + ")) as NhaCungCap,  Upper(Rtrim(DH.DiaChiDoiTuong)) as DiaChiNhaCungCap, DH.NguoiLienHe, dbo.Char2Date(DH.NgayCungCap) as NgayGiao,   Upper(Rtrim(DH.DiaChiGiaoHang)) as DiaChiGiaoHang, VC.Ten" + strLanguage + " AS VanChuyen, TT.Ten" + strLanguage + " as ThanhToan,  NV.Ten" + strLanguage + " as NhanVien,   DH.SoHopDong, CT.KhoaHangHoa, HH.Ma as MaHang, Upper(Rtrim(HH.Ten" + strLanguage + ")) As HangHoa,  CT.KhoaDonViTinh, DVT.Ten" + strLanguage + " As DonViTinh, CT.QuyCach, CT.SoLuong,  CT.DonGiaNT, CT.ThanhTienNT, CT.ThueSuat, CT.TienThueNT, DH.DienGiai,DH.TienPhiNT as UPS,   HH.KhoaNhom,NH.Ten" + strLanguage + " As NhomHang , DT.DiaChiGiaoHang as DiaChiGiaoHangKhachhang, LG.Ten" + strLanguage + " as LoaiGia FROM BH_DonDatHang DH  left join BH_DonDatHangChiTiet CT on DH.Khoa = CT.KhoaDonDatHang    left join DM_HangHoa HH on CT.KhoaHangHoa = HH.Khoa   left join DM_NhomHangHoa NH on HH.KhoaNhom = NH.Khoa  left join DM_PhuongThucVanChuyen VC on DH.PhuongThucGiaoHang = VC.Khoa    left join DM_PhuongThucThanhToan TT on DH.PhuongThucThanhToan = TT.Khoa    left join DM_DoiTuong DT on DH.KhoaDoiTuong = DT.Khoa    left join DM_LoaiGia LG on DT.KhoaLoaiGia = LG.Khoa  left join DM_DoiTuong NV on DH.KhoaNhanVien = NV.Khoa     LEFT JOIN DM_DonViTinh DVT on CT.KhoaDonViTinh = DVT.Khoa      WHERE CT.KhoaDonDatHang = '" + strKhoa + "' ORDER BY CT.Khoa";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrintPhanTichDonHang(string strKhoa, string strLanguage)
        {
            DataTable table;
            try
            {
                string commandText = "  SELECT Upper(KH.Ten" + modGeneral.H_LANGUAGE + ") As KhachHang, DH.NguoiLienHe, DH.DiaChiGiaoHang AS DiaChi, KH.DienThoai, KH.MaSoThue,  dbo.Char2Date(DH.NgayCungCap) As NgayGiaoHang, dbo.Char2Date(DH.NgayHangVeKho) As NgayHenThanhToan, DH.LoaiTien, HH.Ten" + modGeneral.H_LANGUAGE + " As HangHoa, HH.Ma As MaHang, DVT.Ten" + modGeneral.H_LANGUAGE + " As DonViTinh, CT.SoLuong, CT.GiaMuaNT as DonGiaDauVao,  CT.TienMuaNT as ThanhTienDauVao, CC.TenViet As NhaCungCap,  CT.DonGiaNT as DonGiaDauRa, CT.ThanhTienNT as ThanhTienDauRa, CT.ThueSuat, CT.TienThueNT as TienThue,  DH.TienHangNT As TongTienHang, DH.TienThueNT As TongTienThue, DH.DauVaoNT As TongDauVao, DH.HoaHongNT As HoaHong  FROM BH_DonDatHang DH  LEFT JOIN DM_DoiTuong KH ON DH.KhoaDoiTuong = KH.Khoa LEFT JOIN BH_DonDatHangChiTiet CT ON DH.Khoa = CT.KhoaDonDatHang LEFT JOIN DM_HangHoa HH ON CT.KhoaHangHoa = HH.Khoa  LEFT JOIN DM_DonViTinh DVT ON HH.KhoaDonViTinh = DVT.Khoa  LEFT JOIN DM_DoiTuong CC ON CT.KhoaNhaCungCap = CC.Khoa  WHERE DH.Khoa = '" + strKhoa + "'";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrintSaleOrder(string strKhoa, string strLanguage)
        {
            DataTable table;
            try
            {
                string commandText = "  SELECT DH.SoChungTu, dbo.Char2Date(DH.NgayChungTu) as NgayChungTu, Upper(RTrim(DT.Ten" + strLanguage + ")) as NhaCungCap,  Upper(Rtrim(DT.DiaChi)) as DiaChiNhaCungCap, DH.NguoiLienHe, dbo.Char2Date(DH.NgayCungCap) as NgayGiao,   Upper(Rtrim(DH.DiaChiGiaoHang)) as DiaChiGiaoHang, VC.Ten" + strLanguage + " AS VanChuyen, TT.Ten" + strLanguage + " as ThanhToan,  NV.Ten" + strLanguage + " as NhanVien,   DH.SoHopDong, CT.KhoaHangHoa, HH.Ma as MaHang, Upper(Rtrim(HH.Ten" + strLanguage + ")) As HangHoa,  CT.KhoaDonViTinh, DVT.Ten" + strLanguage + " As DonViTinh, CT.QuyCach, CT.SoLuong,  CT.DonGiaNT, CT.ThanhTienNT, CT.ThueSuat, CT.TienThueNT, DH.DienGiai,DH.TienPhiNT as UPS,   HH.KhoaNhom,NH.Ten" + strLanguage + " As NhomHang , DT.DiaChiGiaoHang as DiaChiGiaoHangKhachhang, LG.TenViet as LoaiGia FROM BH_DonDatHang DH  left join BH_DonDatHangChiTiet CT on DH.Khoa = CT.KhoaDonDatHang    left join DM_HangHoa HH on CT.KhoaHangHoa = HH.Khoa   left join DM_NhomHangHoa NH on HH.KhoaNhom = NH.Khoa  left join DM_PhuongThucVanChuyen VC on DH.PhuongThucGiaoHang = VC.Khoa    left join DM_PhuongThucThanhToan TT on DH.PhuongThucThanhToan = TT.Khoa    left join DM_DoiTuong DT on DH.KhoaDoiTuong = DT.Khoa    left join DM_LoaiGia LG on DT.KhoaLoaiGia = LG.Khoa  left join DM_DoiTuong NV on DH.KhoaNhanVien = NV.Khoa     LEFT JOIN DM_DonViTinh DVT on CT.KhoaDonViTinh = DVT.Khoa      WHERE CT.KhoaDonDatHang = '" + strKhoa + "' ORDER BY CT.Khoa";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDetails(string strKhoa)
        {
            DataTable table;
            try
            {
                string commandText = " SELECT CT.Khoa, CT.KhoaHangHoa, HH.Ma as MaHang, HH.Ten" + modGeneral.H_LANGUAGE + " HangHoa,  CT.KhoaDonViTinh, DVT.Ten" + modGeneral.H_LANGUAGE + " As DonViTinh, CT.QuyCach, CT.SoLuong, CT.SoLuongCungCap,  CT.DonGiaNT, CT.ThanhTienNT, CT.ThueSuat, CT.TienThueNT, CT.GiaMuaNT, CT.TienMuaNT, CT.KhoaNhaCungCap, CC.Ten" + modGeneral.H_LANGUAGE + " As NhaCungCap, CT.TyLeHoaHong, CT.HoaHongNT, CT.SoLuongCungCap  FROM BH_DonDatHangChiTiet CT left join DM_HangHoa HH on CT.KhoaHangHoa = HH.Khoa  LEFT JOIN DM_DonViTinh DVT on CT.KhoaDonViTinh = DVT.Khoa  LEFT JOIN DM_DoiTuong CC on CT.KhoaNhaCungCap = CC.Khoa  WHERE CT.KhoaDonDatHang = '" + strKhoa + "' ORDER BY CT.Khoa";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDetailsIntoHoaDon(string strKhoa)
        {
            DataTable table;
            try
            {
                string commandText = " SELECT CT.Khoa, CT.KhoaHangHoa, HH.Ma as MaHang, HH.Ten" + modGeneral.H_LANGUAGE + " HangHoa,  CT.KhoaDonViTinh, DVT.Ten" + modGeneral.H_LANGUAGE + " As DonViTinh, CT.QuyCach, CT.SoLuong, CT.SoLuongCungCap,  CT.DonGiaNT as DonGia, CT.ThanhTienNT as TienHang, CT.ThueSuat, CT.TienThueNT as TienThue, HH.KhoaTKHangHoa,  TK.SoTaiKhoan as TaiKhoanHangHoa, HH.KhoaTKGiaVon, TK.SoTaiKhoan as TaiKhoanGiaVon  FROM BH_DonDatHangChiTiet CT left join DM_HangHoa HH on CT.KhoaHangHoa = HH.Khoa  LEFT JOIN DM_DonViTinh DVT on CT.KhoaDonViTinh = DVT.Khoa  LEFT JOIN DM_TaiKhoan TK on HH.KhoaTKHangHoa = TK.Khoa  WHERE CT.KhoaDonDatHang = '" + strKhoa + "'";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetList(string strCondition = "")
        {
            DataTable table;
            string str2 = "";
            try
            {
                if (strCondition.Trim() != "")
                {
                    str2 = " WHERE " + strCondition;
                }
                string commandText = "SELECT DH.Khoa, DH.SoChungTu, dbo.Char2Date(DH.NgayChungTu) as Ngay, DT.Ten" + modGeneral.H_LANGUAGE + " as NhaCungCap,  dbo.Char2Date(DH.NgayCungCap)As HanGiaoHang, IsNull(DH.TienHangNT,0) + IsNull(DH.TienThueNT,0) + IsNull(DH.TienPhiNT,0) as SoTienNT, IsNull(DH.TienHang,0) + IsNull(DH.TienThue,0) + IsNull(DH.TienPhi,0) as SoTien, DC.TenViet as TinhTrang, DH.DienGiai FROM BH_DonDatHang DH LEFT JOIN DM_DoiTuong DT ON DH.KhoaDoiTuong = DT.Khoa LEFT JOIN HT_DUNGCHUNG DC ON DH.TinhTrang = DC.Ma " + str2 + " ORDER BY DH.NgayChungTu, DH.SoChungTu";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public bool IsDuplicateVoucherNo(string strVoucherNo, string strKeyTable, string strLoai)
        {
            string commandText = "SELECT * FROM BH_DonDatHang Where Rtrim(SoChungTu) = '" + strVoucherNo.Trim() + "' AND Khoa <> '" + strKeyTable + "' AND LoaiChungTu <> '" + strLoai + "'";
            return (DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]) > 0);
        }

        public bool Load(string pKhoa)
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[2];
            try
            {
                string commandText = "SELECT * FROM BH_DonDatHang WHERE Khoa = '" + pKhoa + "'";
                IDataReader dataReader = DBHelper.ExecuteReader(modGeneral.ConnectionString, CommandType.Text, commandText, commandParameters);
                if (dataReader.Read())
                {
                    this.mKhoa = Conversions.ToString(modGeneral.GetValue(dataReader, 0, modGeneral.typeOfColumn.GetString));
                    this.mSoChungTu = Conversions.ToString(modGeneral.GetValue(dataReader, 1, modGeneral.typeOfColumn.GetString));
                    this.mNgayChungTu = Conversions.ToString(modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetString));
                    this.mKhoaDoiTuong = Conversions.ToString(modGeneral.GetValue(dataReader, 3, modGeneral.typeOfColumn.GetString));
                    this.mDiaChiDoiTuong = Conversions.ToString(modGeneral.GetValue(dataReader, 4, modGeneral.typeOfColumn.GetString));
                    this.mNguoiLienHe = Conversions.ToString(modGeneral.GetValue(dataReader, 5, modGeneral.typeOfColumn.GetString));
                    this.mNgayCungCap = Conversions.ToString(modGeneral.GetValue(dataReader, 6, modGeneral.typeOfColumn.GetString));
                    this.mKhoaLoaiGia = Conversions.ToString(modGeneral.GetValue(dataReader, 7, modGeneral.typeOfColumn.GetString));
                    this.mHanGiaoCuoi = Conversions.ToString(modGeneral.GetValue(dataReader, 8, modGeneral.typeOfColumn.GetString));
                    this.mKhoaNhanVien = Conversions.ToString(modGeneral.GetValue(dataReader, 9, modGeneral.typeOfColumn.GetString));
                    this.mDiaChiGiaoHang = Conversions.ToString(modGeneral.GetValue(dataReader, 10, modGeneral.typeOfColumn.GetString));
                    this.mSoHopDong = Conversions.ToString(modGeneral.GetValue(dataReader, 11, modGeneral.typeOfColumn.GetString));
                    this.mPhuongThucGiaoHang = Conversions.ToString(modGeneral.GetValue(dataReader, 12, modGeneral.typeOfColumn.GetString));
                    this.mPhuongThucThanhToan = Conversions.ToString(modGeneral.GetValue(dataReader, 13, modGeneral.typeOfColumn.GetString));
                    this.mDienGiai = Conversions.ToString(modGeneral.GetValue(dataReader, 14, modGeneral.typeOfColumn.GetString));
                    this.mLoaiChungTu = Conversions.ToString(modGeneral.GetValue(dataReader, 15, modGeneral.typeOfColumn.GetString));
                    this.mLoaiTien = Conversions.ToString(modGeneral.GetValue(dataReader, 0x10, modGeneral.typeOfColumn.GetString));
                    this.mTyGia = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x11, modGeneral.typeOfColumn.GetDecimal));
                    this.mTienHangNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x12, modGeneral.typeOfColumn.GetDecimal));
                    this.mTienHang = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x13, modGeneral.typeOfColumn.GetDecimal));
                    this.mTienThueNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 20, modGeneral.typeOfColumn.GetDecimal));
                    this.mTienThue = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x15, modGeneral.typeOfColumn.GetDecimal));
                    this.mTienPhiNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x16, modGeneral.typeOfColumn.GetDecimal));
                    this.mTienPhi = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x17, modGeneral.typeOfColumn.GetDecimal));
                    this.mDauVaoNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x18, modGeneral.typeOfColumn.GetDecimal));
                    this.mDauVao = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x19, modGeneral.typeOfColumn.GetDecimal));
                    this.mHoaHongNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x1a, modGeneral.typeOfColumn.GetDecimal));
                    this.mHoaHong = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x1b, modGeneral.typeOfColumn.GetDecimal));
                    this.mKhoaBaoGia = Conversions.ToString(modGeneral.GetValue(dataReader, 0x1c, modGeneral.typeOfColumn.GetString));
                    this.mKhoaDonVi = Conversions.ToString(modGeneral.GetValue(dataReader, 0x1d, modGeneral.typeOfColumn.GetString));
                    this.mKhoaNhanVienTao = Conversions.ToString(modGeneral.GetValue(dataReader, 30, modGeneral.typeOfColumn.GetString));
                    this.mNgayTao = Conversions.ToString(modGeneral.GetValue(dataReader, 0x1f, modGeneral.typeOfColumn.GetString));
                    this.mKhoaNhanVienSua = Conversions.ToString(modGeneral.GetValue(dataReader, 0x20, modGeneral.typeOfColumn.GetString));
                    this.mNgaySua = Conversions.ToString(modGeneral.GetValue(dataReader, 0x21, modGeneral.typeOfColumn.GetString));
                    this.mTinhTrang = Conversions.ToString(modGeneral.GetValue(dataReader, 0x22, modGeneral.typeOfColumn.GetString));
                    this.mNgayHopDong = Conversions.ToString(modGeneral.GetValue(dataReader, 0x23, modGeneral.typeOfColumn.GetString));
                    this.mNgayHangVeKho = Conversions.ToString(modGeneral.GetValue(dataReader, 0x24, modGeneral.typeOfColumn.GetString));
                    this.mKiemTra = Conversions.ToInteger(modGeneral.GetValue(dataReader, 0x25, modGeneral.typeOfColumn.GetInt32));
                    this.mKhoaNhanVienDuyet = Conversions.ToString(modGeneral.GetValue(dataReader, 0x26, modGeneral.typeOfColumn.GetString));
                    this.mNgayDuyet = Conversions.ToString(modGeneral.GetValue(dataReader, 0x27, modGeneral.typeOfColumn.GetString));
                }
                dataReader.Close();
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool Save()
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[0x27];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, this.mKhoa);
                commandParameters[1] = DBHelper.createParameter("@SoChungTu", DbType.Int64, ParameterDirection.Input, this.mSoChungTu);
                commandParameters[2] = DBHelper.createParameter("@NgayChungTu", DbType.Int64, ParameterDirection.Input, this.mNgayChungTu);
                commandParameters[3] = DBHelper.createParameter("@KhoaDoiTuong", DbType.Int64, ParameterDirection.Input, this.mKhoaDoiTuong);
                commandParameters[4] = DBHelper.createParameter("@DiaChiDoiTuong", DbType.Int64, ParameterDirection.Input, this.mDiaChiDoiTuong);
                commandParameters[5] = DBHelper.createParameter("@NguoiLienHe", DbType.Int64, ParameterDirection.Input, this.mNguoiLienHe);
                commandParameters[6] = DBHelper.createParameter("@NgayCungCap", DbType.Int64, ParameterDirection.Input, this.mNgayCungCap);
                commandParameters[7] = DBHelper.createParameter("@KhoaLoaiGia", DbType.Int64, ParameterDirection.Input, this.mKhoaLoaiGia);
                commandParameters[8] = DBHelper.createParameter("@HanGiaoCuoi", DbType.Int64, ParameterDirection.Input, this.mHanGiaoCuoi);
                commandParameters[9] = DBHelper.createParameter("@KhoaNhanVien", DbType.Int64, ParameterDirection.Input, this.mKhoaNhanVien);
                commandParameters[10] = DBHelper.createParameter("@DiaChiGiaoHang", DbType.Int64, ParameterDirection.Input, this.mDiaChiGiaoHang);
                commandParameters[11] = DBHelper.createParameter("@SoHopDong", DbType.Int64, ParameterDirection.Input, this.mSoHopDong);
                commandParameters[12] = DBHelper.createParameter("@PhuongThucGiaoHang", DbType.Int64, ParameterDirection.Input, this.mPhuongThucGiaoHang);
                commandParameters[13] = DBHelper.createParameter("@PhuongThucThanhToan", DbType.Int64, ParameterDirection.Input, this.mPhuongThucThanhToan);
                commandParameters[14] = DBHelper.createParameter("@DienGiai", DbType.Int64, ParameterDirection.Input, this.mDienGiai);
                commandParameters[15] = DBHelper.createParameter("@LoaiChungTu", DbType.Int64, ParameterDirection.Input, this.mLoaiChungTu);
                commandParameters[0x10] = DBHelper.createParameter("@LoaiTien", DbType.Int64, ParameterDirection.Input, this.mLoaiTien);
                commandParameters[0x11] = DBHelper.createParameter("@TyGia", DbType.Date, ParameterDirection.Input, this.mTyGia);
                commandParameters[0x12] = DBHelper.createParameter("@TienHangNT", DbType.Date, ParameterDirection.Input, this.mTienHangNT);
                commandParameters[0x13] = DBHelper.createParameter("@TienHang", DbType.Date, ParameterDirection.Input, this.mTienHang);
                commandParameters[20] = DBHelper.createParameter("@TienThueNT", DbType.Date, ParameterDirection.Input, this.mTienThueNT);
                commandParameters[0x15] = DBHelper.createParameter("@TienThue", DbType.Date, ParameterDirection.Input, this.mTienThue);
                commandParameters[0x16] = DBHelper.createParameter("@TienPhiNT", DbType.Date, ParameterDirection.Input, this.mTienPhiNT);
                commandParameters[0x17] = DBHelper.createParameter("@TienPhi", DbType.Date, ParameterDirection.Input, this.mTienPhi);
                commandParameters[0x18] = DBHelper.createParameter("@DauVaoNT", DbType.Date, ParameterDirection.Input, this.mDauVaoNT);
                commandParameters[0x19] = DBHelper.createParameter("@DauVao", DbType.Date, ParameterDirection.Input, this.mDauVao);
                commandParameters[0x1a] = DBHelper.createParameter("@HoaHongNT", DbType.Date, ParameterDirection.Input, this.mHoaHongNT);
                commandParameters[0x1b] = DBHelper.createParameter("@HoaHong", DbType.Date, ParameterDirection.Input, this.mHoaHong);
                commandParameters[0x1c] = DBHelper.createParameter("@KhoaBaoGia", DbType.Int64, ParameterDirection.Input, this.mKhoaBaoGia);
                commandParameters[0x1d] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, this.mKhoaDonVi);
                commandParameters[30] = DBHelper.createParameter("@KhoaNhanVienTao", DbType.Int64, ParameterDirection.Input, this.mKhoaNhanVienTao);
                commandParameters[0x1f] = DBHelper.createParameter("@NgayTao", DbType.Int64, ParameterDirection.Input, this.mNgayTao);
                commandParameters[0x20] = DBHelper.createParameter("@KhoaNhanVienSua", DbType.Int64, ParameterDirection.Input, this.mKhoaNhanVienSua);
                commandParameters[0x21] = DBHelper.createParameter("@NgaySua", DbType.Int64, ParameterDirection.Input, this.mNgaySua);
                commandParameters[0x22] = DBHelper.createParameter("@TinhTrang", DbType.Int64, ParameterDirection.Input, this.mTinhTrang);
                commandParameters[0x23] = DBHelper.createParameter("@NgayHopDong", DbType.Int64, ParameterDirection.Input, this.mNgayHopDong);
                commandParameters[0x24] = DBHelper.createParameter("@NgayHangVeKho", DbType.Int64, ParameterDirection.Input, this.mNgayHangVeKho);
                commandParameters[0x25] = DBHelper.createParameter("@KiemTra", DbType.Double, ParameterDirection.Input, this.mKiemTra);
                commandParameters[0x26] = DBHelper.createParameter("@pError", DbType.Double, ParameterDirection.Output, 0);
                DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "BH_sp_DonDatHang", commandParameters);
                if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectNotEqual(commandParameters[0x26].Value, 0, false))
                {
                    return false;
                }
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public void SetBlank()
        {
            this.mKhoa = "";
            this.mSoChungTu = "";
            this.mNgayChungTu = "";
            this.mKhoaDoiTuong = "";
            this.mDiaChiDoiTuong = "";
            this.mNguoiLienHe = "";
            this.mNgayCungCap = "";
            this.mHanGiaoCuoi = "";
            this.mKhoaNhanVien = "";
            this.mDiaChiGiaoHang = "";
            this.mSoHopDong = "";
            this.mPhuongThucGiaoHang = "";
            this.mPhuongThucThanhToan = "";
            this.mDienGiai = "";
            this.mLoaiChungTu = "";
            this.mLoaiTien = "";
            this.mTyGia = 0.0;
            this.mTienHangNT = 0.0;
            this.mTienHang = 0.0;
            this.mTienThueNT = 0.0;
            this.mTienThue = 0.0;
            this.mTienPhiNT = 0.0;
            this.mTienPhi = 0.0;
            this.mKhoaBaoGia = "";
            this.mKhoaDonVi = "";
            this.mKhoaNhanVienTao = "";
            this.mNgayTao = "";
            this.mKhoaNhanVienSua = "";
            this.mNgaySua = "";
            this.mTinhTrang = "";
            this.mNgayHopDong = "";
            this.mNgayHangVeKho = "";
        }

        public bool TrungSoChungTu(string pSoCT, string pKhoa)
        {
            bool flag2;
            string commandText = "";
            IDataParameter parameter = null;
            try
            {
                commandText = "SELECT * FROM BH_DonDatHang WHERE RTRIM(SoChungTu) = '" + pSoCT.Trim() + "' AND RTRIM(Khoa) <> '" + pKhoa.Trim() + "'";
                bool flag = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[] { parameter }).Tables[0].Rows.Count > 0;
                flag2 = flag;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                flag2 = true;
                ProjectData.ClearProjectError();
                return flag2;
                ProjectData.ClearProjectError();
            }
            return flag2;
        }

        public double DauVao
        {
            get
            {
                return this.mDauVao;
            }
            set
            {
                this.mDauVao = value;
            }
        }

        public double DauVaoNT
        {
            get
            {
                return this.mDauVaoNT;
            }
            set
            {
                this.mDauVaoNT = value;
            }
        }

        public string DiaChiDoiTuong
        {
            get
            {
                return this.mDiaChiDoiTuong;
            }
            set
            {
                this.mDiaChiDoiTuong = value;
            }
        }

        public string DiaChiGiaoHang
        {
            get
            {
                return this.mDiaChiGiaoHang;
            }
            set
            {
                this.mDiaChiGiaoHang = value;
            }
        }

        public string DienGiai
        {
            get
            {
                return this.mDienGiai;
            }
            set
            {
                this.mDienGiai = value;
            }
        }

        public string HanGiaoCuoi
        {
            get
            {
                return this.mHanGiaoCuoi;
            }
            set
            {
                this.mHanGiaoCuoi = value;
            }
        }

        public double HoaHong
        {
            get
            {
                return this.mHoaHong;
            }
            set
            {
                this.mHoaHong = value;
            }
        }

        public double HoaHongNT
        {
            get
            {
                return this.mHoaHongNT;
            }
            set
            {
                this.mHoaHongNT = value;
            }
        }

        public string Khoa
        {
            get
            {
                return this.mKhoa;
            }
            set
            {
                this.mKhoa = value;
            }
        }

        public string KhoaBaoGia
        {
            get
            {
                return this.mKhoaBaoGia;
            }
            set
            {
                this.mKhoaBaoGia = value;
            }
        }

        public string KhoaDoiTuong
        {
            get
            {
                return this.mKhoaDoiTuong;
            }
            set
            {
                this.mKhoaDoiTuong = value;
            }
        }

        public string KhoaDonVi
        {
            get
            {
                return this.mKhoaDonVi;
            }
            set
            {
                this.mKhoaDonVi = value;
            }
        }

        public string KhoaLoaiGia
        {
            get
            {
                return this.mKhoaLoaiGia;
            }
            set
            {
                this.mKhoaLoaiGia = value;
            }
        }

        public string KhoaNhanVien
        {
            get
            {
                return this.mKhoaNhanVien;
            }
            set
            {
                this.mKhoaNhanVien = value;
            }
        }

        public string KhoaNhanVienDuyet
        {
            get
            {
                return this.mKhoaNhanVienDuyet;
            }
            set
            {
                this.mKhoaNhanVienDuyet = value;
            }
        }

        public string KhoaNhanVienSua
        {
            get
            {
                return this.mKhoaNhanVienSua;
            }
            set
            {
                this.mKhoaNhanVienSua = value;
            }
        }

        public string KhoaNhanVienTao
        {
            get
            {
                return this.mKhoaNhanVienTao;
            }
            set
            {
                this.mKhoaNhanVienTao = value;
            }
        }

        public int KiemTra
        {
            get
            {
                return this.mKiemTra;
            }
            set
            {
                this.mKiemTra = value;
            }
        }

        public string LoaiChungTu
        {
            get
            {
                return this.mLoaiChungTu;
            }
            set
            {
                this.mLoaiChungTu = value;
            }
        }

        public string LoaiTien
        {
            get
            {
                return this.mLoaiTien;
            }
            set
            {
                this.mLoaiTien = value;
            }
        }

        public string NgayChungTu
        {
            get
            {
                return this.mNgayChungTu;
            }
            set
            {
                this.mNgayChungTu = value;
            }
        }

        public string NgayCungCap
        {
            get
            {
                return this.mNgayCungCap;
            }
            set
            {
                this.mNgayCungCap = value;
            }
        }

        public string NgayDuyet
        {
            get
            {
                return this.mNgayDuyet;
            }
            set
            {
                this.mNgayDuyet = value;
            }
        }

        public string NgayHangVeKho
        {
            get
            {
                return this.mNgayHangVeKho;
            }
            set
            {
                this.mNgayHangVeKho = value;
            }
        }

        public string NgayHopDong
        {
            get
            {
                return this.mNgayHopDong;
            }
            set
            {
                this.mNgayHopDong = value;
            }
        }

        public string NgaySua
        {
            get
            {
                return this.mNgaySua;
            }
            set
            {
                this.mNgaySua = value;
            }
        }

        public string NgayTao
        {
            get
            {
                return this.mNgayTao;
            }
            set
            {
                this.mNgayTao = value;
            }
        }

        public string NguoiLienHe
        {
            get
            {
                return this.mNguoiLienHe;
            }
            set
            {
                this.mNguoiLienHe = value;
            }
        }

        public string PhuongThucGiaoHang
        {
            get
            {
                return this.mPhuongThucGiaoHang;
            }
            set
            {
                this.mPhuongThucGiaoHang = value;
            }
        }

        public string PhuongThucThanhToan
        {
            get
            {
                return this.mPhuongThucThanhToan;
            }
            set
            {
                this.mPhuongThucThanhToan = value;
            }
        }

        public string SoChungTu
        {
            get
            {
                return this.mSoChungTu;
            }
            set
            {
                this.mSoChungTu = value;
            }
        }

        public string SoHopDong
        {
            get
            {
                return this.mSoHopDong;
            }
            set
            {
                this.mSoHopDong = value;
            }
        }

        public double TienHang
        {
            get
            {
                return this.mTienHang;
            }
            set
            {
                this.mTienHang = value;
            }
        }

        public double TienHangNT
        {
            get
            {
                return this.mTienHangNT;
            }
            set
            {
                this.mTienHangNT = value;
            }
        }

        public double TienPhi
        {
            get
            {
                return this.mTienPhi;
            }
            set
            {
                this.mTienPhi = value;
            }
        }

        public double TienPhiNT
        {
            get
            {
                return this.mTienPhiNT;
            }
            set
            {
                this.mTienPhiNT = value;
            }
        }

        public double TienThue
        {
            get
            {
                return this.mTienThue;
            }
            set
            {
                this.mTienThue = value;
            }
        }

        public double TienThueNT
        {
            get
            {
                return this.mTienThueNT;
            }
            set
            {
                this.mTienThueNT = value;
            }
        }

        public string TinhTrang
        {
            get
            {
                return this.mTinhTrang;
            }
            set
            {
                this.mTinhTrang = value;
            }
        }

        public double TyGia
        {
            get
            {
                return this.mTyGia;
            }
            set
            {
                this.mTyGia = value;
            }
        }
    }
}

